// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UcExecDiffInfo.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   The uc exec diff info.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.WinClient.Forms.DbItems
{
    using System.ComponentModel;
    using System.Data;
    using Common.Helper;
    using Common.Model;
    using DiffControl;

    /// <summary>
    /// The uc exec diff info.
    /// </summary>
    public class UcExecDiffInfo : UcItemInfoBase
    {
        /// <summary>
        /// The _dbobjectstable.
        /// </summary>
        private readonly DatabaseObjectTypes _dbobjectstable;

        /// <summary>
        /// The _databases.
        /// </summary>
        private Databases _databases;

        /// <summary>
        /// The diff view.
        /// </summary>
        private DiffView diffView;

        /// <summary>
        /// Initializes a new instance of the <see cref="UcExecDiffInfo"/> class.
        /// </summary>
        /// <param name="itemInfoRow">
        /// The item info row.
        /// </param>
        /// <param name="databases">
        /// The databases.
        /// </param>
        /// <param name="windowButton">
        /// The window button.
        /// </param>
        /// <param name="dbobjectstable">
        /// The dbobjectstable.
        /// </param>
        public UcExecDiffInfo(DataRow itemInfoRow, Databases databases, bool windowButton, 
                              DatabaseObjectTypes dbobjectstable)
            : base(itemInfoRow, windowButton)
        {
            this.InitializeComponent();
            this._dbobjectstable = dbobjectstable;

            this._isButtons = false;
            this.DiffViewInit(databases);
        }


        /// <summary>
        /// The diff view init.
        /// </summary>
        /// <param name="databases">
        /// The databases.
        /// </param>
        private void DiffViewInit(Databases databases)
        {
            string sp1Text = string.Empty;
            string sp2Text = string.Empty;
            this._databases = databases;

            this.diffView.Init(string.Empty, string.Empty);

            // sp1
            sp1Text = this._databases.DatabaseLeft.DatabaseObjects.SqlScripting.Script(this._schema, this._name, this._dbobjectstable);

            // sp2
            sp2Text = this._databases.DatabaseRight.DatabaseObjects.SqlScripting.Script(this._schema, this._name, this._dbobjectstable);
            this.diffView.Init(sp1Text, sp2Text);
        }


        /// <summary>
        /// The init.
        /// </summary>
        /// <param name="itemInfoRow">
        /// The item info row.
        /// </param>
        /// <param name="databases">
        /// The databases.
        /// </param>
        /// <param name="windowButton">
        /// The window button.
        /// </param>
        public void Init(DataRow itemInfoRow, Databases databases, bool windowButton)
        {
            this.Init(itemInfoRow, windowButton);
            this.DiffViewInit(databases);
        }

        /// <summary>
        /// The show form.
        /// </summary>
        protected override void ShowForm()
        {
            UcExecDiffInfo spDiffInfo = new UcExecDiffInfo(this._itemInfoRow, this._databases, false, this._dbobjectstable);
            frmItemInfoForm itemInfoform = new frmItemInfoForm(spDiffInfo);
            itemInfoform.ShowDialog();
        }

        #region Designer generated code
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
            }
            base.Dispose(disposing);
        }
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.diffView = new DiffControl.DiffView();
            this.panelMain.SuspendLayout();
            this.panelButton.SuspendLayout();
            this.SuspendLayout();
            // 
            // panelMain
            // 
            this.panelMain.Controls.Add(this.diffView);
            this.panelMain.Name = "panelMain";
            this.panelMain.Controls.SetChildIndex(this.diffView, 0);
            // 
            // panelButton
            // 
            this.panelButton.Name = "panelButton";
            // 
            // btnOk
            // 
            this.btnOk.Name = "btnOk";
            // 
            // btnCancel
            // 
            this.btnCancel.Name = "btnCancel";
            // 
            // btnModify
            // 
            this.btnModify.Name = "btnModify";
            // 
            // btnDelete
            // 
            this.btnDelete.Name = "btnDelete";
            // 
            // btnNew
            // 
            this.btnNew.Name = "btnNew";
            // 
            // btnClose
            // 
            this.btnClose.Name = "btnClose";
            // 
            // diffView
            // 
            this.diffView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                | System.Windows.Forms.AnchorStyles.Left)
                | System.Windows.Forms.AnchorStyles.Right)));
            this.diffView.Location = new System.Drawing.Point(8, 64);
            this.diffView.Name = "diffView";
            this.diffView.Size = new System.Drawing.Size(472, 216);
            this.diffView.TabIndex = 10;
            // 
            // UcExecDiffInfo
            // 
            this.Name = "UcExecDiffInfo";
            this.panelMain.ResumeLayout(false);
            this.panelButton.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion
    }
}